home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / comm / tcp / Netdial4_0.lha / AmiTCP_Netdial4.0 / netdial.rexx < prev    next >
OS/2 REXX Batch file  |  1980-05-28  |  11KB  |  328 lines

  1. /* dialnet.rexx                                                           */
  2. /*                                                                        */
  3. /* Version 1.0, 11 December 1993, by P.J. Rovero                          */
  4. /*         1.2, 19 December 1993                                          */
  5. /*         1.3, 30 December 1993, by K. Raquel Sanborn (raquels@uhunix)   */
  6. /*         1.4, 3  January  1994, Fix reboot Amiga without lose of CSLIP  */
  7. /*         1.5, 5  January  1994, Fix mounting of APIPE:                  */
  8. /*         1.6, 6  January  1994, Add BREAK C support and "PROTECT +S"    */
  9. /*         1.7, 6  January  1994, Add FAILTAT 21 for mount >NIL: APIPE:   */
  10. /*         2.0, 20 December 1994, Redesign by Wes Tatters                 */
  11. /*                                  for AmiTCP 4.0                        */
  12. /*                                Now uses parameter passing instead of   */
  13. /*                                script building.                        */
  14. /*                                Calls dialnet.connect to launch AmiTCP  */
  15. /*         2.1, 1 March 1995,     Configured for AUSNET @ world.net       */
  16. /*                                This service needs Login: before Slip:  */ 
  17. /*                                                                        */
  18. /* An ARexx script that will dial a terminal server, connect, determine   */
  19. /* the dynamically assigned IP address, and start the proper components   */
  20. /* of AmiTCP 4.x.  The script uses rexxserdev.library v5.x by Joseph M.   */
  21. /* Stivaletta.                                                            */
  22. /*                                                                        */
  23. /* Inspired by Dave Bolen's REXX/2 SLIPUP.CMD for IBM OS/2 TCPIP 1.2.1    */
  24. /*                                                                        */
  25. /* and AmiTCP_dialup10 by K. Raquel Sanborn                               */
  26. /*                                                                        */
  27. /* ---------------------------------------------------------------------- */
  28.  
  29. /* Define general strings and other initialization stuff                     */
  30.  
  31. say 'Setting Control Variables...'
  32.  
  33. cr         = '0d'x
  34. crlf       = '0d0a'x
  35. lf         = '0a'x
  36.  
  37. say 'Setting User Variables...'
  38.  
  39. dtimeout   = 30                              /* Dial time out in Seconds  */
  40. ctimeout   = 15                              /* Connect time out in Secs  */
  41.  
  42.  
  43. /************************   SITE INFORMATION   ****************************/
  44.  
  45. /* These variables should be altered to reflect your local connection     */
  46.  
  47. slip_ip    = '0.0.0.0'                       /* Assigned at Login         */
  48. host_name  = 'World.net'                     /* Ausnet Domain Name        */
  49. host_ip    = '192.190.215.5'                 /* Ausnet - World.net        */
  50.  
  51. dialstr    = 'ATDT 131494'||cr        /* Put your Telephone Number      */
  52.  
  53. logprompt  = 'sername:'                 /* Put your Login Prompt here     */
  54. passprompt = 'assword:'                 /* Put your Password Prompt here  */
  55. slipprompt = '>'                        /* Put your Server Prompt here    */
  56.  
  57. slip_cmd   = 'slip /compressed default'||cr /* Slip start command goes here */
  58. iptype     = 'cslip0'                        /* slip0 for SLIP sites   */
  59.                                              /* cslip0 for CSLIP sites */
  60.  
  61. /************************   USER INFORMATION  *****************************/
  62. /*                                                                        */
  63. /*              AUSNET USERS ONLY NEED TO SET THESE LINES                 */
  64.  
  65. amiganame  = 'wtatters'       /* put your Amiga user name here  */
  66. username   = 'wtatters'||cr   /* Ausnet user name here - same as amigname*/
  67. passwd     = 'passwordamiga'||cr /* Put Ausnet passwd here    */
  68.  
  69. /*                                                                        */
  70. /**************************************************************************/
  71.  
  72.  
  73. say 'Setting Modem Variables...'
  74.  
  75.   at_cmd        = 'AT'||cr
  76.   response      = 'OK'
  77.   modeminit     = 'ATZ'||cr
  78.   modemescape   = '+++'
  79.  
  80.   connectstr    = 'CONNECT'
  81.   busystr       = 'BUSY'
  82.   nocarrierstr  = 'NO CARRIER'
  83.   nodialtonestr = 'NO DIALTONE'  
  84.  
  85.  
  86. /**************************************************************************/
  87.  
  88.  
  89. /* Start the required libraries                      */
  90.  
  91.     say 'Opening libraries...'
  92.  
  93.     check = addlib('rexxsupport.library', 0, -30, 0)
  94.     if (check == 0) then say 'rexxsupport library did not open...'
  95.  
  96.     check = addlib('rexxserdev.library',  0, -30, 0)
  97.     if (check == 0) then say 'rexxserdev did not open...'
  98.  
  99. /* Open the serial device and talk to the modem                          */
  100.  
  101.     say 'Setting up serial device...'
  102.     serhandle = SerOpen('serial.device', 0)
  103.     check     = SerClear(serhandle)
  104.     check     = SerSetParms( serhandle, 19200, 8, N, 1, 0 )
  105.  
  106. /* Clean up on "BREAK C" */
  107.  
  108.     buffer = allocmem( 4096 )
  109.     junk   = c2d( buffer )
  110.     signal on break_c
  111.  
  112. /* Initialize Modem                                                     */
  113.  
  114.     say 'Initializing Modem'
  115.     result = SerWrite( serhandle, '+++', length( '+++' ) )
  116.     check  = delay(200)
  117.  
  118.     result = SerWrite( serhandle, modeminit, length( modeminit ) )
  119.  
  120.     say 'Waiting for '||response
  121.     call wait_str( response )
  122.  
  123. /* Dial & wait for a connection and the modem status string */
  124.  
  125.     dtime = 0
  126.  
  127.     say 'Dialing the terminal server... '
  128.     check    = 0
  129.     do forever
  130.         if (check == 0) then
  131.     do
  132.         result = SerWrite( serhandle, dialstr, length( dialstr))
  133.             check = 1
  134.             totalstr = ''
  135.         end
  136.     status   = SerQuery( serhandle )
  137.         parse upper var status valid bytes_read status_bits .
  138.         rcvdstr  = SerRead( serhandle, junk, bytes_read )
  139.         totalstr = totalstr||rcvdstr
  140.  
  141.         dtime = dtime + 1
  142.  
  143.         if ( dtime >= dtimeout ) then
  144.         do
  145.            say Dialer timed out !!!
  146.            result = break_c()
  147.         end
  148.  
  149.         say "Dialing: "||totalstr
  150.  
  151.         test = pos(connectstr, totalstr)
  152.         if (test ~= 0) then leave
  153.  
  154.         test = pos(busystr, totalstr)
  155.         if (test ~= 0) then
  156.         do 
  157.            result = delay( 500 )
  158.            check = 0     
  159.         end
  160.  
  161.         test = pos(nocarrierstr, totalstr)
  162.         if (test ~= 0) then exit 20
  163.  
  164.         test = pos(nodialtonestr, totalstr)
  165.         if (test ~= 0) then exit 20
  166.  
  167.         result   = delay(100)
  168.     end
  169.  
  170.    totalstr = ''
  171.  
  172.    say 'Modem has connected to the terminal server...'
  173.    check = delay(50)
  174.    check = SerFlush( serhandle, 'R')
  175.    check = delay(50)
  176.  
  177. /* send CR to wake up terminal server                                      */
  178.  
  179.    say 'Sent CR to server...'
  180.    check = SerWrite( serhandle, cr, length( cr ))
  181.  
  182.     say 'Waiting for CSLIP Server... '
  183.     check    = 0
  184.     online   = 0
  185.     totalstr = ''
  186.  
  187.     ctime = 0
  188.  
  189.     do forever
  190.     status   = SerQuery( serhandle )
  191.         parse upper var status valid bytes_read status_bits .
  192.         rcvdstr  = SerRead( serhandle, junk, bytes_read )
  193.         totalstr = totalstr||rcvdstr
  194.  
  195.         say totalstr
  196.  
  197.         ctime = ctime + 1
  198.  
  199.         if ( ctime >= ctimeout ) then 
  200.         do
  201.            say Dialer could not negotiate connection !!!
  202.           result = break_c()
  203.         end
  204.  
  205.         test = pos( 'No response', totalstr )
  206.         if ( test ~= 0 ) then
  207.         do
  208.           say 'Connection failed  ...'
  209.           result = break_c()
  210.         end
  211.  
  212.         test = pos( logprompt, totalstr )
  213.         if ( test ~= 0 ) then
  214.         do
  215.           ctime = 0
  216.           totalstr = ''
  217.           online = online + 1
  218.           say 'Received user prompt...'
  219.           check = SerWrite( serhandle, username, length( username ))
  220.           check = SerRead(  serhandle, junk, length(username))
  221.           say 'Sent Username, now waiting for password prompt...'
  222.         end
  223.  
  224.         test = pos( passprompt, totalstr )
  225.         if ( test ~= 0 ) then
  226.         do
  227.           ctime = 0
  228.           totalstr = ''
  229.           online = online + 2
  230.           say 'Received password prompt...'
  231.           check = SerWrite( serhandle, passwd, length( passwd ))
  232.           say 'Sent password, now waiting for Terminal...'
  233.         end
  234.  
  235.         test = pos( slipprompt, totalstr )
  236.         if ( test ~= 0 ) then
  237.         do
  238.           ctime = 0
  239.           totalstr = ''
  240.           online = online + 3
  241.           say 'Received Connection prompt sending CSlip Command ...'
  242.           check = SerWrite( serhandle, slip_cmd, length( slip_cmd ) )
  243.           check = SerRead( serhandle, junk, length( slip_cmd ) )
  244.         end
  245.  
  246.         if (online == 6) then leave
  247.  
  248.         result  = delay(100)
  249.     end
  250.  
  251.     totalstr = ''
  252.  
  253.     say 'Connection completed, now wait for IP addresses...'
  254.  
  255.     address command
  256.     'wait 2 secs'
  257.     call wait_str('address')
  258.     say 'CSLIP address received from Host system...'
  259.  
  260.  
  261. /* Ok, now we have all the data we need to start Cslip           */
  262. /* Close down the serial port but leave the line up (ignore DTR) */
  263.  
  264.     check = SerClose( serhandle )
  265.  
  266.     result = startslip()
  267.     check = freemem(buffer,4096)
  268.  
  269. exit result
  270.  
  271. /* ------------------------------------------------------------- */
  272. /* Exit point for "Break C" or ^C                                */
  273. /* ------------------------------------------------------------- */
  274.  
  275. break_c:
  276.  
  277.     say 'Cleaning up before exit...'
  278.  
  279.     say 'Initializing Modem'
  280.     result = SerWrite( serhandle, '+++', length( '+++' ) )
  281.  
  282.     check  = delay(200)
  283.     result = SerWrite( serhandle, modeminit, length( modeminit ) )
  284.  
  285.     check = SerClose( serhandle )    
  286.     say 'Serial Port closed'
  287.  
  288.     check = freemem(buffer,4096)
  289.  
  290. exit
  291.  
  292. /* ------------------------------------------------------------- */
  293. /* procedure startslip                                           */
  294. /*                                                               */
  295. /* Start and configure AmiTCP for SLIP                           */
  296. /* ------------------------------------------------------------- */
  297.  
  298. startslip:
  299.  
  300.     parse var rcvdstr . 'IP address is ' a '.' b '.' c '.' d '.'.
  301.     slip_ip = a||'.'||b||'.'||c||'.'||d
  302.  
  303.     say 'AmiTCP:bin/netdial.connect starting'
  304.     'AmiTCP:bin/netdial.connect '||host_name||' '||host_ip||' '||slip_ip||' '||amiganame||' '||iptype
  305.  
  306. return 0
  307.  
  308.  
  309. /* ------------------------------------------------------------- */
  310. /* Subroutine wait_str  returns when argument string is received */
  311. /* ------------------------------------------------------------- */
  312. wait_str:
  313.  
  314.     teststr = arg(1)
  315.     check = 0
  316.     do until (check ~= 0)
  317.         status = SerQuery( serhandle )
  318.         parse upper var status valid bytes_read status_bits .
  319.         rcvdstr = SerRead( serhandle, junk, bytes_read )
  320.         check   = pos(teststr,rcvdstr)
  321.         test    = delay(50)
  322.     end
  323.  
  324. return
  325.  
  326.  
  327.  
  328.